package com.alennus.blog.utils;

import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Clark on 2016/9/18.
 */
@Component
public class FileUploadValidator {

    public  static final String IMAGE_PATTERN =
    "([^\\s]+(\\.(?i)(jpg|png|gif|bmp|jpeg))$)";

    public  static final String DOC_PATTERN =
            "([^\\s]+(\\.(?i)(doc|xls|ppt|docx|xlsx|pptx|pdf|zip|rar|7z))$)";

    public FileUploadValidator(){

    }


    public boolean validate(final String filePattern, final String name){
        Pattern pattern =  Pattern.compile(filePattern);
        Matcher matcher = pattern.matcher(name);
        return matcher.matches();
    }

}
